package controller.utils;

import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import model.entities.Item;



@ManagedBean(name="itemConverter")
public class ItemsConverter  implements Converter {

	
	@Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
		System.out.println("getAsString " + value);
		if(value != null)
		{
			return ((Item)value).getId().toString();	
		}
		return "" ;
    }
	
	@Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
		System.out.println("getAsObject " + value);
		if(value != null){
        return SelectItemsUtils.findValueByStringConversion(context, component, value, this);
		}
		Item item = null ;
		return item; 
    }
	
}

